package com.itheima.health.job;


import com.itheima.health.service.OrderSettingService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;


@JobHandler(value = "heima.ordersetting.clean.job") //  web配置JobHandler的名称
@Component
public class CleanOderSettingJob extends IJobHandler {

    @Reference
    private OrderSettingService orderSettingService;

    /**
     * 但是spring的@Scheduled只支持6位，年份是不支持的，带年份的7位格式会报错：
     * Cron expression must consist of 6 fields (found 7 in "1/5 * * * * ? 2018")
     * 通过cron表达式 来配置 该方法的执行周期
     * **/
    @Override
    public ReturnT<String> execute(String s) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        //Date date=new Date();
        String str="2020-07-06";
        Date date=sdf.parse(str);
        orderSettingService.deleteOrderSettingByDate(date);
        System.out.println("删除成功");
        return SUCCESS;
    }

}

